﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using baseSet.importExport;
using dhsystem.Main;
using dhSystemBLL.produceBLL;
using dhDataAcess.baseBLL;

namespace dhsystem.produceForm.Stock
{
    public partial class FrmV_StockInDetail : Form
    {
        public FrmV_StockInDetail()
        {
            InitializeComponent();
        }

        private void FrmV_StockInDetail_Load(object sender, EventArgs e)
        {
            packStockInBLL packStockIn = new packStockInBLL();
           // pdckBLL pdck = new pdckBLL();
            // orderProduceListBLL orderProduceLsit = new orderProduceListBLL();
            //string orderNo = dGridorder.CurrentRow.Cells["orderNo"].Value.ToString();
            bindingSourcepdck.DataSource = packStockIn.getpackStockInDetailAll ();
            dGridpdck.DataSource = bindingSourcepdck;
            DcolumnSet.colSet(moduleInfo.packStockInDetail , dGridpdck);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridpdck.RowCount.ToString() + "条";
        }

        private void toolQuery_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.packStockInDetail);
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridpdck.DataSource = query.rTable;
            }
        }

        private void toolExport_Click(object sender, EventArgs e)
        {

            FrmExcelExport frm = new FrmExcelExport(moduleInfo.packStockInDetail, dGridpdck, "出库信息");
            frm.ShowDialog();
        }

        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonQuery_Click(object sender, EventArgs e)
        {
            try
            {
                baseSet.Query q = new baseSet.Query(null, dhDataAcess.baseBLL.dataConn.connOpen());
                bindingSourcepdck.DataSource = q.sqlQueryLikeAll(moduleInfo.packStockInDetail, textMatNameQuery.Text.ToString().Trim());
                dGridpdck.DataSource = bindingSourcepdck;
                DcolumnSet.colSet(moduleInfo.packStockInDetail, dGridpdck);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void buttupdate_Click(object sender, EventArgs e)
        {
            packStockInBLL packStockIn = new packStockInBLL();
            // pdckBLL pdck = new pdckBLL();
            // orderProduceListBLL orderProduceLsit = new orderProduceListBLL();
            //string orderNo = dGridorder.CurrentRow.Cells["orderNo"].Value.ToString();
            bindingSourcepdck.DataSource = packStockIn.getpackStockInDetailAll();
            dGridpdck.DataSource = bindingSourcepdck;
            DcolumnSet.colSet(moduleInfo.packStockInDetail, dGridpdck);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridpdck.RowCount.ToString() + "条";
        }

        private void dGridpdck_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            decimal count = 0;
            for (int i = 0; i < dGridpdck.SelectedRows.Count; i++)
            {
                if (dGridpdck.SelectedRows[i].Cells[dGridpdck.CurrentCell.ColumnIndex].Value != null)
                {
                    try
                    {
                        count = count + decimal.Parse(dGridpdck.SelectedRows[i].Cells[dGridpdck.CurrentCell.ColumnIndex].Value.ToString());
                    }
                    catch (Exception)
                    {
                        continue;//非数字时,会报错,跳过
                    }
                }
            }
            if (count == 0)
            {
                this.textBox1.Text = "";
            }
            else
            {
                this.textBox1.Text = "求和=" + count.ToString();
            }
        }
    }
}
